package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.domain.Novel;
import com.example.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/BookShelfListServlet")
public class BookShelfListServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        request.setCharacterEncoding("utf-8");
        User user=(User) request.getSession().getAttribute("user");
        int user_id=user.getUser_id();
        NovelDao novelDao=new NovelDao();
        List<Novel> bookshelfList=novelDao.getBookshelfList(user_id);
        if (bookshelfList.size()==0){
            request.setAttribute("msg","您还没有添加小说哦");
            request.getRequestDispatcher("bookshelf.jsp").forward(request, response);
            return;
        }
        request.setAttribute("bookshelfList",bookshelfList);
        request.getRequestDispatcher("bookshelf.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request,response);
    }
}
